﻿using Authentication.Model.Interface;
using Authentication.Model.Model;
using Common.Contract.Authentication.Record;
using Common.Contract.Authentication.Request;
using Common.Contract.Authentication.Response;
using Common.Contract.Paging;
using Common.Service.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Authentication.Core.ServiceCommand
{
    public class RetrieveCustomerCountByGroupServiceCommand : ProviderServiceCommand<IProviderFactory, RetrieveCustomerCountByGroupRequest, RetrieveCustomerCountByGroupResponse>
    {
        public RetrieveCustomerCountByGroupServiceCommand(IProviderFactory providers) : base(providers) { }
        protected override void Validate(RetrieveCustomerCountByGroupRequest request)
        {

        }

        protected override bool OnExecute(RetrieveCustomerCountByGroupResponse response)
        {
            bool isSuccess = true;
            string errorMessage = string.Empty;

            List<AccountGroupCustomer> result = Providers.AccountGroupCustomers.RetrieveAccountGroupCustomer(Request.Dao, Request.IsNew);
            response.Records = result.Select(x => new CustomerGroupCountRecord
            {
                GroupCode = x.GroupCode,
                TotalCustomer = String.Format("{0:#,##0}", x.TotalCustomer.Value),
                NewCustomerByCif = String.Format("{0:#,##0}", x.NewByCif.Value),
                NewCustomerByRule = String.Format("{0:#,##0}", x.NewByRule.Value)
            }).ToList();
            return isSuccess;
        }
    }
}
